<?php

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/

Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
    return $request->user();
});

//start
Route::group(['prefix' => '/v1' ], function (){

    Route::post('/auth/signup', [\App\Http\Controllers\AuthController::class, 'userSignup']);
    Route::post('/auth/signin', [\App\Http\Controllers\AuthController::class, 'userSignin']);

    Route::get('/games/{slug}/scores', [\App\Http\Controllers\ScoresController::class, 'gameScores']);
    Route::get('/games/{slug}', [\App\Http\Controllers\GameController::class, 'gameInfo']);
    Route::get('/games', [\App\Http\Controllers\GameController::class, 'getGames']);


    //需登入
    Route::middleware(['userAuth'])->group(function (){
        Route::post('/auth/signout', [\App\Http\Controllers\AuthController::class, 'userSignout']);
        Route::post('/games/{slug}/scores', [\App\Http\Controllers\ScoresController::class, 'addScore']);
        Route::post('/games', [\App\Http\Controllers\GameController::class, 'addGame']);

        Route::get('/users/games/scores', [\App\Http\Controllers\ScoresController::class, 'getTopScore']);
        Route::get('/user/games/{slug}/scores', [\App\Http\Controllers\ScoresController::class, 'getUserGameTop']);
        Route::delete('/user/games/{slug}', [\App\Http\Controllers\GameController::class, 'delGame']);
        Route::put('/user/games/{slug}', [\App\Http\Controllers\GameController::class, 'updateGame']);
        Route::get('/users/games', [\App\Http\Controllers\GameController::class, 'getUserGame']);
    });

});
